package com.cn.wanxi.servlet.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.AboutDesignerService;
import com.cn.wanxi.service.NewsFindAllService;
import com.cn.wanxi.service.impl.AboutDesignerServiceImpl;
import com.cn.wanxi.service.impl.NewsFindAllServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/news/findAllNews")
public class NewsFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //      0.乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String type = req.getParameter("type");
        NewsModel newsModel = new NewsModel();
        if (type != null ) {
            newsModel.setType(Integer.parseInt(type));
        }
        //3.调用服务逻辑层
        ResultModel resultModel =new ResultModel();
        Map map=new HashMap();
        NewsFindAllService newsFindAllService = new NewsFindAllServiceImpl();
        map.put("NewsModel",newsFindAllService.getNewsFindAll(newsModel));
        resultModel.setData(map);
        //4.返回前端需要的数据
        resp.getWriter().print(JSONObject.toJSONString(resultModel));
    }
}
